<template>
    <div class="section_common">
        <div class="main">
            <el-form ref="form" label-width="100px">
                <el-form-item label="入职日期">
                    <el-input v-model="entryDate" size="mini"></el-input>
                </el-form-item>

                <el-form-item label="工号">
                    <el-input v-model="jobnum" size="mini"></el-input>
                </el-form-item>
                <el-form-item label="姓名">
                    <el-input v-model="user" size="mini"></el-input>
                </el-form-item>
                <el-form-item label="部门名">
                    <el-input v-model="deptName" size="mini"></el-input>
                </el-form-item>
                <el-form-item label="消息周期">
                    <el-input v-model="cycle" size="mini"></el-input>
                </el-form-item>

                <!-- 弹出框 -->
                <van-dialog v-model="agreeShow" show-cancel-button :before-close="chargeAgreeBtn">
                    <!--<van-field label="新人数据情况" type="textarea" class="title_input" v-model="condition" placeholder="请输入新人数据情况"/>-->
                    <el-form-item label="新人数据情况">
                        <el-input v-model="condition" type="textarea" size="mini"></el-input>
                    </el-form-item>
                </van-dialog>

                <van-dialog v-model="show" show-cancel-button :before-close="chargeBtn">
                    <!-- 输入框 -->
                    <!--<van-field v-model="reason" rows="1" autosize label="驳回原因" type="textarea" placeholder="请输入驳回原因"/>-->
                    <el-form-item label="驳回原因">
                        <el-input v-model="reason" type="textarea" size="mini"></el-input>
                    </el-form-item>
                </van-dialog>

                <el-form-item>
                    <el-button id="isAgree" v-bind:disabled="isShow" type="primary" size="mini" @click="submitAgree">{{message}}</el-button>
                    <el-button id="isNotAgree" v-bind:disabled="isShow" type="primary" size="mini" @click="submitNotAgree">{{message1}}</el-button>
                </el-form-item>

            </el-form>
        </div>
    </div>
</template>
<script>
    import Vue from 'vue';
    import {Toast,Picker,Popup,Dialog} from 'vant';
    Vue.use(Picker);
    Vue.use(Popup);
    Vue.use(Dialog)



    export default {

        data() {
            return {
                id:"",//入职管理对应的id
                sixid:"",//入职60天表数据对应的id
                entryDate: "",//入职时间
                jobnum:"",
                user:"",//用户名
                cycle:"",
                deptName:"",
                condition:"",
                reason:"",

                title: "销售部入职转正",
                editManagement: '/mobiles/editSixManagement',

                isShow:false,
                message:"符合",
                message1:"驳回",
                show:false,
                agreeShow:false

            };
        },

        created() {
            this.nowUser=JSON.parse(localStorage.getItem('userInfo')).userId;
            this.id= this.$route.params.id;
            this.getManagementInfo();
        },

        methods: {

            //根据入职管理的id找到相对应的入职管理详情
            getManagementInfo(){
                this.$https.post('/mobiles/getManagementInfo',{
                    nowUser:this.nowUser,
                    id:this.id
                }).then((res)=>{
                    console.log(res.data.data);
                    this.entryDate=res.data.data.entryDate;
                    this.jobnum=res.data.data.jobnum;
                    this.user=res.data.data.user;
                    this.deptName=res.data.data.deptName;
                    this.cycle=res.data.data.cycle;
                    if (res.data.data.sixSubmit=='0'){
                        this.isShow=true;
                        if (res.data.data.msg!=null){
                            this.message1="已驳回";
                        }else {
                            this.message="已通过";
                        }

                    }
                }).catch(err => {
                    console.log(err);
                })
            },

            // 返回
            goBack() {
                this.$router.go(-1);
            },

            // 提交同意
            submitAgree() {
                this.agreeShow=true;
            },
            chargeAgreeBtn(action,done){
                if (action==='cancel'){
                    done();
                }else if (action==='confirm'){
                    if (!this.isConditionNull()){
                        done();
                        return false;
                    }else {
                        this.show=false;
                        this.$https.post('/mobiles/editSixManagement', {
                            userId:this.nowUser,
                            id:this.id,
                            condition:this.condition,
                        }).then(() => {
                            Toast("已通过");
                        }).catch(err => {
                            console.log(err)
                        });
                    }

                }
            },
            //驳回
            submitNotAgree() {
                this.show=true;
            },
            chargeBtn(action,done){
                if (action==='cancel'){
                    done();
                }else if (action==='confirm'){
                    if (!this.isNull()){
                        done();
                        return false;
                    }
                    this.show=false;
                    this.$https.post('/mobiles/editSixManagement', {
                        userId:this.nowUser,
                        id:this.id,
                        reason:this.reason,
                    }).then(() => {
                        Toast("已驳回");
                        this.getDetail();//找到对应的页面详情，及领导信息
                    }).catch(err => {
                        console.log(err)
                    });
                }
            },

            //判断相关数据是否为空
            isNull() {
                if (this.reason == '') {
                    this.$toast("请填写驳回原因");
                    return false;
                }

                return true;
            },
            isConditionNull() {
                if (this.condition == '') {
                    this.$toast("请填写新人数据情况");
                    return false;
                }

                return true;
            },

        },
    };
</script>

<style lang="scss" scoped>
    .main {
        background-color: white;
        .el-form {
            padding-right: 10px;
            .el-form-item {
                .el-form-item__label {
                    line-height: 16px;
                }
                margin-bottom: 5px;
            }
        }
    }
</style>
